package com.atguigu.guli.service.api.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class GatewayConfig  {
    //配置跨域的过滤器
    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedHeader("*");//允许携带所有的请求头跨域访问
        configuration.addAllowedMethod("*");//允许所有的请求方式跨域访问
        configuration.addAllowedOrigin("*");//允许所有的客户端跨域访问
        configuration.setAllowCredentials(true);//雨荨携带cookie跨域访问
        source.registerCorsConfiguration("/**",configuration);//通配所有的路径访问
        return new CorsWebFilter(source);
    }
    //跨域配置的filter

}
